package top.wineye.spring.dependency.inject;

import jakarta.annotation.Resource;
import jakarta.inject.Inject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import top.wineye.spring.dependency.pojo.Biz;



public class InjectByField {

    // @Autowired OK 虽然 idea 会提示错误 但是能够成功运行 (会忽略掉静态字段 static)
    //
    @Resource  //
    Biz biz1;

    @Inject  // 根据名称注入
            // @Inject 需要依赖于 JSR-330的 jar 包
    Biz biz;

    public static void main(String[] args) {

        // 这种情况下，injectByField 类本身也讲被注册为 bean
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(InjectByField.class);

        InjectByField injectByField = context.getBean(InjectByField.class);

        System.out.println(injectByField.biz);
        System.out.println(injectByField.biz1);

        context.close();;
    }

    @Bean
    public Biz biz() {
        Biz biz = new Biz();
        biz.setBiz("abc");
        return biz;
    }

}
